using System;
using System.Collections.Generic;
using System.Text;
using System.Management.Automation;
using System.Collections;
using System.Security;
using agsXMPP.protocol.client;

namespace PoshXmpp
{
    [Cmdlet(VerbsCommunications.Send, "Message")]
    public class SendMessageCommand : XmppCommandBase
    {

        #region Parameters
        [Parameter(Position = 0,
            Mandatory = true,
            HelpMessage = "Jabber Id to send to")]
        [Alias("UserName","Id","Jid","To")]
        [ValidateNotNullOrEmpty]
        public string JabberId { get; set; }

        [Parameter(Position = 1,
            Mandatory = true,
            ValueFromPipeline = true,
            HelpMessage = "Message to send")]
        [ValidateNotNullOrEmpty]
        [Alias("Body","Msg")]
        public string Message { get; set; }

        [Parameter(Position=2,
           Mandatory= false,
           HelpMessage = "Send as single message (instead of chat)")]
        [Alias("Type")]
        public SwitchParameter Single { get; set; }
        
        #endregion

        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            if (Single.ToBool())
            {
               Client.SendMsg(JabberId, Message, MessageType.normal );
            } else Client.SendMsg(JabberId, Message);

            if (Passthru) { WriteObject(Message); }
        }
    }
}
